<!DOCTYPE html>
<html>

  <head>
    <meta charset="UTF-8">
    <title>project add</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/static/super_cmdb/css/font.css">
    <link rel="stylesheet" href="/static/super_cmdb/css/xadmin.css">
  </head>

  <body>
    <div class="x-body">
        <form class="layui-form">
          <div class="layui-form-item">
              <label for="name" class="layui-form-label" style="width: 160px;">
                  <span class="x-red">*</span>项目名称
              </label>
              <div class="layui-input-inline" style="width: 400px;">
                  <input type="text" id="name" name="name" required="" lay-verify="required"
                  autocomplete="off"  class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="name_en" class="layui-form-label" style="width: 160px;">
                  <span class="x-red">*</span>项目英文名
              </label>
              <div class="layui-input-inline" style="width: 400px;">
                  <input type="text" id="name_en" name="name_en" required="" lay-verify="required" placeholder="zombie"
                  autocomplete="off"  class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="describe" class="layui-form-label" style="width: 160px;">
                  <span class="x-red">*</span>工作室
              </label>
              <div class="layui-input-inline">
                  <textarea id="describe" name="describe" style="margin: 0px;width: 400px;height: 40px;"></textarea>
              </div>
          </div>

          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label" style="width: 160px;">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">
                  添加
              </button>
          </div>
      </form>
    </div>
    <script type="text/javascript" src="/static/super_cmdb/js/jquery.min.js"></script>
    <script type="text/javascript" src="/static/super_cmdb/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/super_cmdb/js/xadmin.js"></script>
    <script type="text/javascript" src="/static/super_cmdb/js/jquery.cookie.js"></script>
        <script>

        $(function () {
            $.ajaxSetup({
                beforeSend:function (xhr,settings) {
                    xhr.setRequestHeader("X-CSRFtoken",$.cookie("csrftoken"));
                }
            })
        });

      layui.use(['form','layer'], function(){
          $ = layui.jquery;
        var form = layui.form
        ,layer = layui.layer;

        //监听提交
        form.on('submit(add)', function(data){
          console.log(data);
          //发异步，把数据提交给php
            $.ajax({
                    url: "/super_cmdb/project_add/",
                    type: "POST",
                    //data: $('#layui-form').serialize(),
                    data: {
                        "name":$("#name").val(),
                        "name_en":$("#name_en").val(),
                        "describe":$("#describe").val()
                        },
                    success: function (data) {
                        console.log(data);
                        if (data.code == 0){
                            layer.alert(data.msg, {icon: 6});
                        } else {
                            layer.alert(data.msg, {icon: 7});
                        }
                    },
                    complete: function () {
                        console.info("添加项目完成......");
                    },
                    error: function (data) {
                        console.info("添加项目出错......");
                    }
                });
                return false;

          {#layer.alert("添加成功", {icon: 6},function () {#}
          {#    // 获得frame索引#}
          {#    var index = parent.layer.getFrameIndex(window.name);#}
          {#    //关闭当前frame#}
          {#    parent.layer.close(index);#}
          //{#});#}
          {#return false;#}
        });
      });

  </script>
  </body>

</html>
